//
//  UserNameAlterViewController.m
//  JiuLe
//
//  Created by 黄鑫 on 16/8/30.
//  Copyright © 2016年 Fine. All rights reserved.
//

#import "UserNameAlterViewController.h"
#import "CLUIBaseViewController.h"
#import "NSString+Check.h"

@interface UserNameAlterViewController ()
@property (weak, nonatomic) IBOutlet UILabel *labName;
@property (weak, nonatomic) IBOutlet UITextField *textFieldName;

@end

@implementation UserNameAlterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改登录用户名";
    [self showNavgationWithLeftItemWithTitle:@"返回"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.labName.text = self.strName;
}

- (IBAction)changeUserName:(id)sender {
    if (![_textFieldName.text checkUserName]) {
        TIPSFORVIEW(@"用户名格式不合法");
        return;
    }
    [SVProgressHUD showWithStatus:@"修改登录用户名..." maskType:SVProgressHUDMaskTypeClear];
    [[BaseDataRequest alloc] modifyUserName:_textFieldName.text withBlock:^(id responseObject, NSString *status, NSError *error) {
        [SVProgressHUD dismiss];
        if ([status isEqualToString:@"0"]) {
            NSDictionary *result = [responseObject objectForKey:@"result"];
            [NSUserDefaults setObject:[result objectForKey:@"name"] forKey:UserDataName];
            self.labName.text = [[NSUserDefaults standardUserDefaults] objectForKey:UserDataName];
            //[SVProgressHUD showSuccessWithStatus:@"修改用户登录名成功!"];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            if (error != nil) {
                TIPSFORVIEW(@"请检测网络设置");
            }else{
                TIPSFORVIEW([responseObject objectForKey:@"message"]);
            }
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
